<?php
namespace common\widgets;

use backend\modules\rbac\models\Menu;

class MenuTree extends \yii\base\Widget
{
    public function run()
    {
        $newMenu  = new Menu();
        $modelList = $newMenu->tree_list();
        $html = $this->ViewCate($modelList);
        $html = "<ol class='dd-list'>$html</ol>";
        return $html;
    }

    public function ViewCate($menu)
    {
        $html = "";
        foreach ($menu as $v => $k) {
            if (isset($k->tree_children) ) {
                $html .= "<li class='dd-item dd-item'  data-id='".$k->id."'><div class='dd-handle dd-handle'>Drag</div><div class='dd-content'>" . $k->name . "</div><ol class='dd-list'>" . $this->ViewCate($k['tree_children']) . "</ol></li>";
            }
            else {
                $html .= "<li class='dd-item dd-item' data-id='".$k->id."'><div class='dd-handle dd-handle'>Drag</div><div class='dd-content'>" . $k->name . "</div></li>";
            }
        }
        return $html;
    }
}